package com.utility;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;

public class HTTPConnection {

	public static String connect(String url,String proxyHost,String port,String username,String password) throws IOException {
		//final String url = "http://www.marchal.com/";
		// final String proxy = "proxy.mydomain.com";
		// final String port = "8080";
		// final String username = "usr";
		// final String password = "pwd";
		 
		Authenticator.setDefault(new SimpleAuthenticator(username, password));
		URL server = new URL(url);
		Properties systemProperties = System.getProperties();
		systemProperties.setProperty("http.proxyHost", proxyHost);
		systemProperties.setProperty("http.proxyPort", port);
		HttpURLConnection connection = (HttpURLConnection) server
				.openConnection();
		connection.connect();
		InputStream in = connection.getInputStream();
		// readResponse(in);

		BufferedReader rd = new BufferedReader(new InputStreamReader(in));
		String line = "";
		String content = "";
		while ((line = rd.readLine()) != null) {
			content += line;
		}
		rd.close();

		return content;

	}

}
